; 实验13 编写、应用中断例程
; 1.编写并安装int 7ch中断例程
; 功能：显示一个用0结束的字符串，中断例程安装在0000:200h处
; 输入：(dh)=行号,(dl)=列号,(cl)=颜色，ds:si执行字符串首地址
; 输入：无，显示效果
assume cs:code1sg,ds:datasg
datasg segment
    db 'Are you Ok?',0
datasg ends

; 显示调用7ch位置
code1sg segment
start:
        mov ax,datasg
        mov ds,ax
        mov si,0
        mov dh,8
        mov dl,8
        mov cl,789h
        int 7ch

        mov ax,4c00h
        int 21h
code1sg ends
; 7ch安装
code1_install segment
install:    ; init copy source
            mov ax,cs
            mov es,ax
            mov di,offset print
            ; init copy desnation 
            mov ax,0h
            mov ds,ax
            mov si,200h
            ; init copy length
            mov cx,offset printend - offset print
            cld
            rep movsb
            ; init intrep table
            mov ax,0h
            mov es,ax
            mov word ptr es:[7ch*4],200h
            mov word ptr es:[7ch*4+2],0h
            mov ax,4c00h
            int 21h
print:
            push ax
            push cx
            push dx
            push si
            push es
            push di
            mov ax,0b800h
            mov es,ax
            mov di,0

            mov ax,160
            mul dh
            mov di,ax
            mov ax,2
            mul dl
            add di,ax
            mov al,cl
show:       
            mov cl,ds:[si]
            mov ch,0
            jcxz printOK
            mov byte ptr es:[di],cl
            mov byte ptr es:[di+1],al
            inc si
            add di,2
            jmp short show
printOK:
            pop di
            pop es
            pop si
            pop dx
            pop cx
            pop ax
            iret
printend: nop

code1_install ends

; 2.在屏幕中间显示80个！，7ch中断例程，完成loop指令功能
; 参数：(cx)=循环次数，(bx)=位移
codesg2 segment
start:
        mov ax,0b800h
        mov es,ax
        mov di,160*12
        mov bx,offset s - offset se
        mov cx,80
s:
        mov byte ptr es:[di],'!'
        add di,2
        int 7ch
se:
        nop

        mov ax,4c00h
        int 21h
codesg2 ends

codesg2_install segment
install:
            mov ax,cs
            mov es,ax
            mov di,offset print
            ; init copy desnation 
            mov ax,0h
            mov ds,ax
            mov si,200h
            ; init copy length
            mov cx,offset lopend - offset lop
            cld
            rep movsb
            ; init intrep table
            mov ax,0h
            mov es,ax
            mov word ptr es:[7ch*4],200h
            mov word ptr es:[7ch*4+2],0h
            mov ax,4c00h
            int 21h
lop:
            push bp
            mov bp,sp
            dec cx
            jcxz lopret
            add ss:[bp+2],bx
lopret:      
            pop bp
            ret
lopend:     nop

codesg2_install ends

; 3.补全显示的英文
data3sg segment
    s1: db 'Good,better,best,','$'
    s2: db 'Never let is rest,','$'
    s3: db 'Till good is better,','$'
    s4: db 'And,better,best.','$'
    s: dw offset s1,offset s2,offset s3,offset s4
    row: db 2,4,6,8
datasg ends
codesg3 segment
start:
        mov ax,cs
        mov ds,ax
        mov bx,offset s
        mov si,offset row
        mov cx,4
ok:     
        
        ; 调用10h中断的2号子程序-设置光标位置
        mov bh,0
        mov dh,[si]
        mov dl,0
        mov ah,2
        int 10h
        ; 调用21h中断的9号子程序-在光标位置显示字符串
        mov dx,[bx]
        mov ah,9
        int 21h
        inc si
        add bx,2
        loop ok

        mov ax,4c00h
        int 21h

codesg3 ends

end start